package com.phantasy.scene.sceneUnit.baseUnit.things.common
{
	import com.phantasy.scene.sceneUnit.baseUnit.things.avatar.AvatarConstant;
	
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.geom.Matrix;
	import flash.system.ApplicationDomain;

	public class BitmapClipData 
	{
		
		public var url:String;
		public var domain:ApplicationDomain;
		private var _source:MovieClip;
		private var key:Vector.<String>;
		private var key_value:Vector.<BitmapFrame>;
		
		public function BitmapClipData()
		{
			
		}
		
		private static function flipHorizontal(bmData:BitmapData):BitmapData
		{
			var _local2:BitmapData = new BitmapData(bmData.width, bmData.height, true, 0);
			var _local3:Matrix = new Matrix();
			_local3.scale(-1, 1);
			_local3.tx = (_local3.tx + bmData.width);
			_local2.draw(bmData, _local3);
			return _local2;
		}
		
		public function set source(mc:MovieClip):void
		{
			if (mc != null)
			{
				this._source = mc;
				this.key = new Vector.<String>();
				this.key_value = new Vector.<BitmapFrame>();
			}
		}
		
		public function getHeight():int
		{
			var _local1:BitmapFrame = this.getFrame(AvatarConstant.ACTION_STAND + "_d" + AvatarConstant.DIR_UP + "_0");
			if (((_local1) && (_local1.data)))
			{
				return (-(_local1.offsetY));
			}
			return 120;
		}
		
		public function getLight(_arg1:String):int
		{
			if (((this._source) && (this._source.hasOwnProperty(_arg1.concat("_l")))))
			{
				return (this._source[_arg1.concat("_l")]);
			}
			return (0);
		}
		
		public function getFrame(_arg1:String):BitmapFrame
		{
			var _local3:Class;
			var _local5:String;
			var _local2:BitmapFrame;
			if (this.key == null)
			{
				return (null);
			}
			var _local4:int = this.key.indexOf(_arg1);
			if (_local4 != -1)
			{
				return (this.key_value[_local4]);
			}
			if (((((!((_arg1.indexOf("_d5") == -1))) || (!((_arg1.indexOf("_d6") == -1))))) || (!((_arg1.indexOf("_d7") == -1)))))
			{
				_local5 = _arg1.replace("_d5", "_d3").replace("_d6", "_d2").replace("_d7", "_d1");
				if (this.domain.hasDefinition(_local5) == false)
				{
					return (null);
				}
				_local3 = (this.domain.getDefinition(_local5) as Class);
				_local2 = new BitmapFrame();
				_local2.data = flipHorizontal(new (_local3)(0, 0));
				_local2.offsetX = -((_local2.data.width + this._source[_local5.concat("_x")]));
				_local2.offsetY = this._source[_local5.concat("_y")];
				if (this._source.hasOwnProperty(_local5.concat("_hold")) == true)
				{
					_local2.hold = this._source[_local5.concat("_hold")];
				};
			}
			else
			{
				if (this.domain.hasDefinition(_arg1) == false)
				{
					return (null);
				}
				_local3 = (this.domain.getDefinition(_arg1) as Class);
				_local2 = new BitmapFrame();
				_local2.data = new (_local3)(0, 0);
				_local2.offsetX = this._source[_arg1.concat("_x")];
				_local2.offsetY = this._source[_arg1.concat("_y")];
				if (this._source.hasOwnProperty(_arg1.concat("_hold")) == true)
				{
					_local2.hold = this._source[_arg1.concat("_hold")];
				}
			}
			this.key.push(_arg1);
			this.key_value.push(_local2);
			return (_local2);
		}

		
	}
}
